class Node:
    '''
    无序列表的节点:
        data:节点数据本身
        next:指向下一个节点的引用
    '''
    def __init__(self, initData):
        self.__data = initData
        self.__next = None

    # def getData(self):
    #     return self.data
    @property
    def data(self):
        return self.__data

    # def setData(self, newData):
    #     self.data = newData
    @data.setter
    def data(self, newData):
        self.__data = newData

    # def getNext(self):
    #     return self.next

    # def setNext(self, newNext):
    #     self.next = newNext
    @property
    def next(self):
        return self.__next

    @next.setter
    def next(self, newnext):
        self.__next = newnext

# temp = Node(39)
# print(temp.data)

class UnorderedList:
    '''
    利用节点建立的无序列表
    '''
    def __init__(self):
        self.head = None

    # @property
    # def head(self):
    #     return self.__head

    def isEmpty(self):
        return self.head == None

    def add(self, item):
        temp = Node(item)
        temp.next = self.head
        self.head = temp

    def size(self):
        current = self.head
        count = 0
        while current != None:
            count +=1
            current = current.next
        return count

    def search(self, item):
        current = self.head
        found = False
        while current !=None and not found:
            if current.data == item:
                found = True
            else:
                current = current.next
        return found

    def remove(self, item):
        previous = None
        current = self.head
        found = False
        while not found:
            if current.data == item:
                found = True
            else:
                previous =current
                current = current.next
        if previous == None:
            self.head = current.next
        else:
            previous.next = current.next

# mylist = UnorderedList()
# # print(mylist.size())
# # print(mylist.isEmpty())

# mylist.add(21)
# # print(mylist.size())

# mylist.add(36)
# # print(mylist.size())
# mylist.add(45)
# print(mylist.remove(36))
# print(mylist.size())